package com.train.implementCallable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 运行
 * {@link ExecutorService}线程池<br/>
 * 调用{@link ExecutorService#submit(Runnable)}执行线程池中的线程<br/>
 * 调用{@link ExecutorService#shutdown()}停止线程池
 * */
public class RunThread {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ImplementCallable callable = new ImplementCallable();
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        Future<Boolean> future_1 = executorService.submit(callable);
        Future<Boolean> future_2 = executorService.submit(callable);
        Future<Boolean> future_3 = executorService.submit(callable);
        // 结束运行
        if ( future_1.get().equals(Boolean.TRUE)
                && future_2.get().equals(Boolean.TRUE)
                && future_3.get().equals(Boolean.TRUE)) {
            executorService.shutdown();
            System.out.println("over");
        }
    }
}